import { EventManager } from '../../engine/EventManager';
import ViewBase from '../../engine/ViewBase';
import { SocketClient } from '../../net/SocketClient';
import { EventConfig } from '../config/EventConfig';
import { UserModel } from '../model/UserModel';
import { UIHelper } from '../util/UIHelper';

const { ccclass, property } = cc._decorator;

@ccclass
export default class ViewRenzheng extends ViewBase {

    onEnable(): void {
        super.onEnable()
        EventManager.instance.on(EventConfig.Event_Update_UserInfo, this.refresh, this)
        let nameedit:cc.EditBox = this.getChild(this.node, "norenzheng/nameedit", cc.EditBox)
        let numedit:cc.EditBox = this.getChild(this.node, "norenzheng/numedit", cc.EditBox)

        let btnSubmit: cc.Node = this.findChild(this.node, "norenzheng/btnSubmit")
        UIHelper.onAddEvent(btnSubmit, () => {
            if(nameedit.string == ""){
                UIHelper.showTip("请输入姓名")
                return;
            }
            if(numedit.string == ""){
                UIHelper.showTip("请输入身份证")
                return;
            }
            SocketClient.req_renzheng(nameedit.string, numedit.string)
        })
        this.refresh()
    }


    private refresh() {
        let norenzheng: cc.Node = this.findChild(this.node, "norenzheng")
        let alrenzheng: cc.Node = this.findChild(this.node, "alrenzheng")
        if (UserModel.instance.isRenzheng) {
            norenzheng.active = false
            alrenzheng.active = true
        }
        else {
            norenzheng.active = true
            alrenzheng.active = false
        }
    }

}
